package org.terrier.matching.models;

import org.terrier.utility.ApplicationSetup;

public class WBpdfL2 extends WeightingModel {
	private static final long serialVersionUID = 1L; 
	/*
	 * you can interface the result by tuning the following parameters
	 */
	/*
     * Weibull pdf 
     */
    double wa = Double.parseDouble(ApplicationSetup.getProperty("distribution.parameter.0", "1.1"));
    double wb = Double.parseDouble(ApplicationSetup.getProperty("distribution.parameter.1", "0.5"));

	public final String getInfo() {
		return "WBpdf"+wa+"_"+wb+"L2_"+c;
	}
	public double score(double tf, double docLength) {
		/*
		 * PL2 normalization
		 */
		double tfn = tf * Idf.log(1 + c * averageDocumentLength / docLength);
		/*
		 * weibull
		 */
		double prob = (wb/tfn) * Math.pow((tfn / wa),wb) * Math.exp(-Math.pow((tfn / wa),wb));
		double inf1 = -Idf.log(prob);
		double inf2 = 1 / (1 + tfn);
		return keyFrequency*inf1 * inf2;
	}
	public double score(//useless here
			double tf,
			double docLength,
			double n_t,
			double F_t,
			double keyFrequency) {
		/*
		 * PL2 normalization
		 */
		double tfn = tf * Idf.log(1 + c * averageDocumentLength / docLength);
		/*
		 * weibull
		 */
		double prob = (wb/tfn) * Math.pow((tfn / wa),wb) * Math.exp(-Math.pow((tfn / wa),wb));
		double inf1 = -Idf.log(prob);
		double inf2 = 1 / (1 + tfn);
		return keyFrequency*inf1 * inf2;
		}
}